Imports System.Configuration

Public Class Common
  Public Shared Function GetConnectionStringByProvider( _
   ByVal providerName As String) As String

    ' Return the connection string for the specified provider. 
    ' If there are multiple connection strings for the 
    ' same provider, the first one found is returned.
    ' Returns Nothing if the provider is not found.

    ' Assume the name won't be found.
    Dim returnValue As String = Nothing

    For Each settings As ConnectionStringSettings In _
     ConfigurationManager.ConnectionStrings
      If settings.ProviderName = providerName Then
        returnValue = settings.ConnectionString
        Exit For
      End If
    Next
    Return returnValue
  End Function

End Class
